
#include <stdint.h>
#include "BooterConfig.h"
#include "Booter.h"
#include "BooterFlag.h"
#include "BooterBoot.h"
#include "BooterUpgrade.h"
#include "Flash.h"
#include "Bsp.h"
#include "BootBsp.h"


void Booter_Init(void){
	Bsp_Init();	
	Flash_Init();
}

uint32_t Booter_CheckMode(void){
	FlashArea_T *App = Flash_GetAppArea();
	if (!Booter_CheckApp(App->Address, App->Size)){
		return MODE_UPGRADE;
	}

	return MODE_BOOT;
}


void Booter_BootApp(void){
	Booter_RunApp();
}

void Booter_UpgradeApp(uint32_t mode){
	Booter_UpgradeInit();
	Booter_Upgrading(mode);
	BSP_Delay_ms(100);
	BSP_UpgradeDeinit();	
	Booter_RunApp();
}

void Booter_Reset(void) {
	BSP_Delay_ms(100);
    NVIC_SystemReset();
}


